<template>
  <div>
    <Swipter />
    <div v-for="sl in songList" :key="sl.id">
      <el-header>
        {{ sl.name }}
      </el-header>
      <el-main>
        <ContentList :contentList="sl.list"></ContentList>
      </el-main>
    </div>
  </div>
</template>

<script>
// 引入Axios
import axios from "axios";
//引入Swiper --轮播图
import Swipter from "../components/Swipter.vue";
//ContentList --展示模块
import ContentList from "../components/ContentList.vue";

export default {
  name: "Home",
  components: {
    Swipter,
    ContentList,
  },
  data() {
    return {
      songList: [
        {
          name: "歌单",
          list: [],
        },
        {
          name: "歌手",
          list: [],
        },
      ],
    };
  },
  created() {
    this.getSongList();
    this.getSinger();
  },
  methods: {
    //获取每日推荐歌单
    getSongList() {
      axios
        .get("http://localhost:3000/top/playlist/highquality?limit=12") //limit 对多为30
        .then((response) => {
          const resultSongList = response.data.playlists.map((item) => ({
            id: item.id,
            name: item.name,
            coverImgUrl: item.coverImgUrl,
            description:item.description,
            copywriter:item.copywriter,
            type:1
          }));
          this.songList[0].list = resultSongList;
        })
        .catch((error) => {
          console.warn(error);
        });
    },
    //获取每日推荐歌手
    getSinger() {
      axios
        .get("http://localhost:3000/top/artists?offset=0&limit=12") //可选参数 : limit: 取出数量 , 默认为 50  offset: 偏移数量 , 用于分页 , 如 :( 页数 -1)*50, 其中 50 为 limit 的值 , 默认 为 0
        .then((response) => {
          const resultHotSinger = response.data.artists.map((item) => ({
            id: item.id,
            name: item.name,
            coverImgUrl: item.picUrl,
            type:2
          }));
          this.songList[1].list = resultHotSinger;
        })
        .catch((error) => {
          console.warn(error);
        });
    },
  },
};
</script>

<style>
.el-header {
  margin-top: 20px;
  background-color: #dee2e6;
  color: #333;
  text-align: center;
  font-size: 22px;
  line-height: 60px;
  font-weight: bold;
}

.el-main {
  background-color: #f8f9fa;
  color: #333;
  text-align: center;
  line-height: 160px;
}
</style>